using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace FluentTags
{

    public class PTag : Tag<PTag>
    {
        public PTag() : base("p"){}
        
        public PTag(string text) : this()
        {
            Controls.Add(new LiteralControl(text));
        }

        public PTag(object value) : this()
        {
            Controls.Add(new LiteralControl(SafeString(value)));
        }
        
        
        public PTag(Control control) : this()
        {
            Controls.Add(control);
        }
        
        
        
        
        public ATag<PTag> A()
        {
            var ctrl = new ATag<PTag>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag A(ATag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public ATag<PTag> A(string text)
        {
            var ctrl = new ATag<PTag>(this);
            Controls.Add(ctrl);
            LiteralControl lc = new LiteralControl(text);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public ATag<PTag> A(Control control)
        {
            var ctrl = new ATag<PTag>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public ATag<PTag> A(object value)
        {
            return A(SafeString(value));
        }
        
        public BTag<PTag> B()
        {
            var ctrl = new BTag<PTag>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag B(BTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public BTag<PTag> B(string text)
        {
            var ctrl = new BTag<PTag>(this);
            Controls.Add(ctrl);
            LiteralControl lc = new LiteralControl(text);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public BTag<PTag> B(Control control)
        {
            var ctrl = new BTag<PTag>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public BTag<PTag> B(object value)
        {
            return B(SafeString(value));
        }
        
        public BRTag<PTag> BR()
        {
            var ctrl = new BRTag<PTag>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag BR(BRTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public EMTag<PTag> EM()
        {
            var ctrl = new EMTag<PTag>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag EM(EMTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public EMTag<PTag> EM(string text)
        {
            var ctrl = new EMTag<PTag>(this);
            Controls.Add(ctrl);
            LiteralControl lc = new LiteralControl(text);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public EMTag<PTag> EM(Control control)
        {
            var ctrl = new EMTag<PTag>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public EMTag<PTag> EM(object value)
        {
            return EM(SafeString(value));
        }
        
        public ITag<PTag> I()
        {
            var ctrl = new ITag<PTag>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag I(ITag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public ITag<PTag> I(string text)
        {
            var ctrl = new ITag<PTag>(this);
            Controls.Add(ctrl);
            LiteralControl lc = new LiteralControl(text);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public ITag<PTag> I(Control control)
        {
            var ctrl = new ITag<PTag>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public ITag<PTag> I(object value)
        {
            return I(SafeString(value));
        }
        
        public ImgTag<PTag> Img()
        {
            var ctrl = new ImgTag<PTag>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag Img(ImgTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public SpanTag<PTag> Span()
        {
            var ctrl = new SpanTag<PTag>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag Span(SpanTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public SpanTag<PTag> Span(string text)
        {
            var ctrl = new SpanTag<PTag>(this);
            Controls.Add(ctrl);
            LiteralControl lc = new LiteralControl(text);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public SpanTag<PTag> Span(Control control)
        {
            var ctrl = new SpanTag<PTag>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public SpanTag<PTag> Span(object value)
        {
            return Span(SafeString(value));
        }
        
        public StrongTag<PTag> Strong()
        {
            var ctrl = new StrongTag<PTag>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag Strong(StrongTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public StrongTag<PTag> Strong(string text)
        {
            var ctrl = new StrongTag<PTag>(this);
            Controls.Add(ctrl);
            LiteralControl lc = new LiteralControl(text);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public StrongTag<PTag> Strong(Control control)
        {
            var ctrl = new StrongTag<PTag>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public StrongTag<PTag> Strong(object value)
        {
            return Strong(SafeString(value));
        }
        
        public SubTag<PTag> Sub()
        {
            var ctrl = new SubTag<PTag>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag Sub(SubTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public SubTag<PTag> Sub(string text)
        {
            var ctrl = new SubTag<PTag>(this);
            Controls.Add(ctrl);
            LiteralControl lc = new LiteralControl(text);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public SubTag<PTag> Sub(Control control)
        {
            var ctrl = new SubTag<PTag>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public SubTag<PTag> Sub(object value)
        {
            return Sub(SafeString(value));
        }
        
        public SupTag<PTag> Sup()
        {
            var ctrl = new SupTag<PTag>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag Sup(SupTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public SupTag<PTag> Sup(string text)
        {
            var ctrl = new SupTag<PTag>(this);
            Controls.Add(ctrl);
            LiteralControl lc = new LiteralControl(text);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public SupTag<PTag> Sup(Control control)
        {
            var ctrl = new SupTag<PTag>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public SupTag<PTag> Sup(object value)
        {
            return Sup(SafeString(value));
        }
        
        
        public PTag Text(string text)
        {
            Controls.Add(new LiteralControl(text));
            return this;
        }

        public PTag Text(object value)
        {
            Controls.Add(new LiteralControl(SafeString(value)));
            return this;
        }
        
    }

    public class PTag<ParentType> : ChildTag<PTag<ParentType>, ParentType>
        where ParentType : HtmlGenericControl
    {
        public PTag(ParentType parent) : base("p", parent) { }

        
        
        
        public ATag<PTag<ParentType>> A()
        {
            var ctrl = new ATag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag<ParentType> A(ATag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public ATag<PTag<ParentType>> A(string text)
        {
            var ctrl = new ATag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(text);
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public ATag<PTag<ParentType>> A(Control control)
        {
            var ctrl = new ATag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public ATag<PTag<ParentType>> A(object value)
        {
            var ctrl = new ATag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(SafeString(value));
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            return ctrl;
        }
        
        public BTag<PTag<ParentType>> B()
        {
            var ctrl = new BTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag<ParentType> B(BTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public BTag<PTag<ParentType>> B(string text)
        {
            var ctrl = new BTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(text);
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public BTag<PTag<ParentType>> B(Control control)
        {
            var ctrl = new BTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public BTag<PTag<ParentType>> B(object value)
        {
            var ctrl = new BTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(SafeString(value));
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            return ctrl;
        }
        
        public BRTag<PTag<ParentType>> BR()
        {
            var ctrl = new BRTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag<ParentType> BR(BRTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public EMTag<PTag<ParentType>> EM()
        {
            var ctrl = new EMTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag<ParentType> EM(EMTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public EMTag<PTag<ParentType>> EM(string text)
        {
            var ctrl = new EMTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(text);
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public EMTag<PTag<ParentType>> EM(Control control)
        {
            var ctrl = new EMTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public EMTag<PTag<ParentType>> EM(object value)
        {
            var ctrl = new EMTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(SafeString(value));
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            return ctrl;
        }
        
        public ITag<PTag<ParentType>> I()
        {
            var ctrl = new ITag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag<ParentType> I(ITag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public ITag<PTag<ParentType>> I(string text)
        {
            var ctrl = new ITag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(text);
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public ITag<PTag<ParentType>> I(Control control)
        {
            var ctrl = new ITag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public ITag<PTag<ParentType>> I(object value)
        {
            var ctrl = new ITag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(SafeString(value));
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            return ctrl;
        }
        
        public ImgTag<PTag<ParentType>> Img()
        {
            var ctrl = new ImgTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag<ParentType> Img(ImgTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public SpanTag<PTag<ParentType>> Span()
        {
            var ctrl = new SpanTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag<ParentType> Span(SpanTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public SpanTag<PTag<ParentType>> Span(string text)
        {
            var ctrl = new SpanTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(text);
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public SpanTag<PTag<ParentType>> Span(Control control)
        {
            var ctrl = new SpanTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public SpanTag<PTag<ParentType>> Span(object value)
        {
            var ctrl = new SpanTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(SafeString(value));
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            return ctrl;
        }
        
        public StrongTag<PTag<ParentType>> Strong()
        {
            var ctrl = new StrongTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag<ParentType> Strong(StrongTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public StrongTag<PTag<ParentType>> Strong(string text)
        {
            var ctrl = new StrongTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(text);
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public StrongTag<PTag<ParentType>> Strong(Control control)
        {
            var ctrl = new StrongTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public StrongTag<PTag<ParentType>> Strong(object value)
        {
            var ctrl = new StrongTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(SafeString(value));
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            return ctrl;
        }
        
        public SubTag<PTag<ParentType>> Sub()
        {
            var ctrl = new SubTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag<ParentType> Sub(SubTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public SubTag<PTag<ParentType>> Sub(string text)
        {
            var ctrl = new SubTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(text);
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public SubTag<PTag<ParentType>> Sub(Control control)
        {
            var ctrl = new SubTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public SubTag<PTag<ParentType>> Sub(object value)
        {
            var ctrl = new SubTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(SafeString(value));
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            return ctrl;
        }
        
        public SupTag<PTag<ParentType>> Sup()
        {
            var ctrl = new SupTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            return ctrl;
        }

        public PTag<ParentType> Sup(SupTag child)
        {
            Controls.Add(child);
            return this;
        }
        
        public SupTag<PTag<ParentType>> Sup(string text)
        {
            var ctrl = new SupTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(text);
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            
            return ctrl;
        }

        public SupTag<PTag<ParentType>> Sup(Control control)
        {
            var ctrl = new SupTag<PTag<ParentType>>(this);
            Controls.Add(ctrl);
            ctrl.Controls.Add(control);
            
            return ctrl;
        }

        public SupTag<PTag<ParentType>> Sup(object value)
        {
            var ctrl = new SupTag<PTag<ParentType>>(this);
            LiteralControl lc = new LiteralControl(SafeString(value));
            Controls.Add(ctrl);
            ctrl.Controls.Add(lc);
            return ctrl;
        }
        
        
        public PTag<ParentType> Text(string text)
        {
            Controls.Add(new LiteralControl(text));
            return this;
        }
        
        public PTag<ParentType> Text(object value)
        {
            Controls.Add(new LiteralControl(SafeString(value)));
            return this;
        }
        
        
    }
}